#!/usr/bin/env node

const http=require('https'),
      log=console.log,
      url=require('url');

const addr=process.argv[2] || 'https://sample.wangding.co/web/one-div.html',
  options=url.parse(global.encodeURI(addr));

options.header={
  'User-Agent':'01-my-curl.js'
};

/*
 *const addr='http://www.baidu.com';
 http.get( addr,res=>... )
 */
http.get(options,res=>{
  //响应起始行
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
  //响应头
  log(res.headers);
  log('');
  res.pipe(process.stdout);//响应体
})

